@extends('layouts.layouts')
@section('title')
    <title>添加视频</title>
    <meta http-equiv="Access-Control-Allow-Origin" content="admin.saipujianshen.com">
@endsection
@section('content')
    <link href="/lib/ueditor/themes/default/css/umeditor.css" type="text/css" rel="stylesheet">
    <script type="text/javascript" charset="utf-8" src="/lib/ueditor/umeditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="/lib/ueditor/umeditor.min.js"></script>
    <script type="text/javascript" src="/lib/ueditor/lang/zh-cn/zh-cn.js"></script>
    <script src="/js/upload.js" type="text/javascript"></script>
    <script src="/js/mobileBUGFix.mini.js" type="text/javascript"></script>
    <link href="/css/ueditor.css" type="text/css" rel="stylesheet">
    <link href="/css/layui.css" type="text/css" rel="stylesheet">
    <style type="text/css">
        .hide{ display:none;}
        .file {
            position: relative;
            display: inline-block;
            background: #D0EEFF;
            border: 1px solid #99D3F5;
            border-radius: 4px;
            padding: 4px 12px;
            overflow: hidden;
            color: #1E88C7;
            text-decoration: none;
            text-indent: 0;
            line-height: 20px;
        }
        .file input {
            position: absolute;
            font-size: 100px;
            right: 0;
            top: 0;
            opacity: 0;
        }
        .file:hover {
            background: #AADFFD;
            border-color: #78C3F3;
            color: #004974;
            text-decoration: none;
        }
    </style>
    <div class="content">
        <div class="header">
            <ul class="breadcrumb">
                <li><a href="/activity/list">社区活动</a> </li>
                <li class="active">活动添加</li>
            </ul>
        </div>
        <div class="main-content">
            <ul class="nav nav-tabs nav-tabs-course">
                <li role="presentation" class="course_add active"><a href="javascript:void(0);">活动添加</a></li>
                <!--<li role="presentation" class="course_hour_add"><a href="javascript:void(0);">课时添加</a></li>-->
            </ul>

 <form class="form-horizontal" id="courseFormInfo" name=theform action="/activity/update/{{$data->id}}"  enctype="multipart/form-data" method="post">
                {{csrf_field()}}
               
            <div class="course_class row">
                    <div class="col-md-8">
                    </br>
                    <div class="form-group">
                         <label for="inputEmail3" class="col-sm-3 control-label">活动标题：</label>
                         <div class="col-sm-9">
                             <input type="text" class="form-control" id="inputEmail3" name="title" placeholder="活动标题" value ="{{$data->title}}">
                         </div>
                    </div>
                    <div class="form-group">
                         <label for="inputEmail3" class="col-sm-3 control-label">活动描述：</label>
                         <div class="col-sm-9">
                             <input type="text" class="form-control" id="inputEmail3" name="description" placeholder="活动描述" value ="{{$data->description}}">
                         </div>
                    </div>
                    <div class="form-group">
                         <label for="inputEmail3" class="col-sm-3 control-label">上传封面图：</label>
                         <div class="col-sm-9">
                                    <a href="javascript:;" class="file">上传封面图
                                        <input type="file" class="upload_img explain" name="explainUrl" placeholder="说明图">
                                    </a>
                                    <img src="{{env('IMG_URL')}}{{$data->cover_url}}" id="explain_img" style="width:120px;max-height:120px;">
                                    <input type="hidden" class="explain_img" name="cover_url" value="{{$data->cover_url}}" />
                         </div>
                    </div>
                    <div class="form-group">
                         <label for="inputEmail3" class="col-sm-3 control-label">跳转链接：</label>
                         <div class="col-sm-9">
                             <input type="text" class="form-control" id="inputEmail3" name="link" placeholder="跳转链接" value ="{{$data->link}}">
                         </div>
                    </div>
                    <div class="form-group">
                         <label for="inputEmail3" class="col-sm-3 control-label">seo标题：</label>
                         <div class="col-sm-9">
                             <input type="text" class="form-control" id="inputEmail3" name="seo_title" placeholder="seo标题" value ="{{$data->seo_title}}">
                         </div>
                    </div>
                    <div class="form-group">
                         <label for="inputEmail3" class="col-sm-3 control-label">seo描述：</label>
                         <div class="col-sm-9">
                             <input type="text" class="form-control" id="inputEmail3" name="seo_description" placeholder="seo描述" value ="{{$data->seo_description}}">
                         </div>
                    </div>
                    <div class="form-group">
                         <label for="inputEmail3" class="col-sm-3 control-label">开始时间：</label>
                         <div class="col-sm-9">
                                 <!-- <div class="layui-input-inline">
                                    <input type="text" class="layui-input" name="start_time1" id="start1" placeholder="">
                                  </div>-->
                                  <div class="layui-input-inline">
                                     <input type="text" class="layui-input" name="start_time" id="start2" placeholder="" value = "{{$data->start_time}}">
                                  </div> ❥
                         </div>
                    </div>
                    <div class="form-group">
                         <label for="inputEmail3" class="col-sm-3 control-label">结束时间：</label>
                         <div class="col-sm-9">
                                 <!-- <div class="layui-input-inline">
                                    <input type="text" class="layui-input" name="end_time1" id="end1" placeholder="">
                                  </div>-->
                                  <div class="layui-input-inline">
                                     <input type="text" class="layui-input" name="end_time" id="end2" placeholder="" value = "{{$data->end_time}}">
                                  </div> ❥
                         </div>
                    </div>
                    <div class="form-group">
                         <label for="inputEmail3" class="col-sm-3 control-label">活动状态：</label>
                         <div class="col-sm-9">
                             <!--<input type="text" class="form-control" id="inputEmail3" name="state" placeholder="1为进行中，0为已结束" value ="{{$data->state}}">-->
							 <input name="state" type="radio" value="1"  @if($data->state == 1) checked="checked"  @endif/>进行中  &nbsp;
							<input name="state" type="radio" value="0" @if($data->state == 0) checked="checked"  @endif/>已结束
                         </div>
                    </div>
                    <div class="form-group">
                         <label for="inputEmail3" class="col-sm-3 control-label">排序：</label>
                         <div class="col-sm-9">
                             <input type="text" class="form-control" id="inputEmail3" name="orderBy" placeholder="排序值越大，越靠前" value="{{$data->orderby}}">
                         </div>
                    </div>
                        
                    </div>
                </div>
                   
                    <div class="row">
                        <p>
                            <button type="submit" class="btn btn-primary btn-lg col-md-offset-5" style="width:120px;background:#286090;color:#fff;">提交</button>
                        </p>
                    </div>

            </form>
        </div>
    </div>
 <script src="/lib/jquery.validate.js" type="text/javascript"></script>
 <script src="/js/layui.js" type="text/javascript"></script>
    <script>
        $("#courseFormInfo").validate({
            onsubmit: true,// 是否在提交是验证
            submitHandler: function (form) {
                var name = $("input[name='name']").val();
				var status = $("input[name = 'status']").val();
				var content = $("input[name = 'content']").val();
                if(name == ''){
                    swal("问题名称未填!");
                    return false;
                }
				if(status == ""){
					swal("状态未选择！");
					return false;
				}
             if(content == "" ){
					swal("请填写内容！");
					return false;
			 }    
                form.submit();
            }
        });
    </script>
   <script type="text/javascript">
    var imgUrl = '{{env('IMG_URL')}}';
        $(".upload_img").UploadImg({
            url : '/course/fileUpload',
            // width : '320',
            //height : '200',
            quality : '0.8', //压缩率，默认值为0.8
            // 如果quality是1 宽和高都未设定 则上传原图
            mixsize : '10000000',
            //type : 'image/png,image/jpg,image/jpeg,image/pjpeg,image/gif,image/bmp,image/x-png',
            before : function(blob,className){
//                var className = '#'+className;
//                $(className).attr('src',blob);
            },
            error : function(res){
                $('#img').attr('src','');
                $('#error').html(res);
            },
            success : function(url,className){
                var idName = '#'+className;
                var className = '.'+className;
                $(idName).attr('src',imgUrl+url);
                $(className).val(url);
            }
        });
   $(".upload_file").click(function(){
        $("#file0").click();
   })
layui.use('laydate', function(){
  var laydate = layui.laydate;
       //常规用法
     /* laydate.render({
        elem: '#start1'
        ,value: '1989-10-14'
        ,isInitValue: true
      });*/
      laydate.render({
        elem: '#start2',
        type:"datetime",
        value: new Date()
      });
      /*laydate.render({
        elem: '#end1'
        ,value: '1989-10-14'
        ,isInitValue: true
      });*/
      laydate.render({
        elem: '#end2',
        type:"datetime",
        value: new Date()
      });
});
 $("#file0").change(function(){
        var objUrl = getObjectURL(this.files[0]) ;
        console.log("objUrl = "+objUrl) ;
        if (objUrl) 
        {
            $("#img0").attr("src", objUrl);
            $("#img0").removeClass("hide");
        }
    }) ;


//建立一個可存取到該file的url
    function getObjectURL(file) 
    {
        var url = null ;
        if (window.createObjectURL!=undefined) 
        { // basic
            url = window.createObjectURL(file) ;
        }
        else if (window.URL!=undefined) 
        {
            // mozilla(firefox)
            url = window.URL.createObjectURL(file) ;
        } 
        else if (window.webkitURL!=undefined) {
            // webkit or chrome
            url = window.webkitURL.createObjectURL(file) ;
        }
        return url ;
    }

   </script>
@endsection